//----------------------------------------------------------------------------
//  ,-.
// /_\___ ,   Ninja Framework
// '  ___\    (C) Riccardo Capra - http://riccar.do
//  //   \\
//----------------------------------------------------------------------------
//  This program is free software: you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation, either version 3 of the License, or
//  (at your option) any later version.
//
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//  GNU General Public License for more details.
//
//  You should have received a copy of the GNU General Public License
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
//----------------------------------------------------------------------------

#include "NjExample01.h"
#include "NjSynchronizationTest.h"
#include "NjExampleRandGenerator.h"
#include "NjDebugSystemWin.h"
#include "NjEventsSystemWin.h"
#include "NjThreadsSystemWin.h"
#include "NjDebugSystemLinux.h"
#include "NjEventsSystemLinux.h"
#include "NjThreadsSystemLinux.h"
#include "NjThreadsSystem.h"
#include "NjTestUnit.h"

//----------------------------------------------------------------------------
#if defined(NJ_PLATFORM_WIN32) || defined(NJ_PLATFORM_WIN64)
int wmain(int iTotArgs, wchar_t const * const * ppArgs)
#elif defined(NJ_PLATFORM_LINUX_X86) || defined(NJ_PLATFORM_LINUX_X86_64)
int main(int iTotArgs, char const * const * ppArgs)
#else
#	error "Unsupported platform configuration"
#endif
{
	NJ_UNUSED_VAR(iTotArgs);
	NJ_UNUSED_VAR(ppArgs);

	printf(	"NJ-SYNC  Copyright (C) 2013  Riccardo Capra\n"
			"This program comes with ABSOLUTELY NO WARRANTY.\n"
			"This is free software, and you are welcome to redistribute it\n"
			"under GNU GPL conditions.\n\n");

	NjDebugSystem::SetImplementation(NjNew(NjDebugSystemPlatform));
	NjEventsSystem::SetImplementation(NjNew(NjEventsSystemPlatform));
	NjThreadsSystem::SetImplementation(NjNew(NjThreadsSystemPlatform));

	NjThreadsSystem::TimeMs uSeed;

	NjBool bSuccess(NjEventsSystem::GetTimeMs(uSeed));
	if (bSuccess)
	{
		EXAMPLE_RAND_GENERATOR::SetSeed(NjUint(uSeed));

		NjSynchronizationTest::Run();

		bSuccess=NjTestUnit::IsUnitTestSuccess();
	}

	NjThreadsSystem::SetImplementation(NJ_NULL);
	NjEventsSystem::SetImplementation(NJ_NULL);
	NjDebugSystem::SetImplementation(NJ_NULL);

	if (!bSuccess)
		return 1;

	return 0;
}
//----------------------------------------------------------------------------
